$(function () {
  getUserInfo();
  $("#btnlogout").click(function () {
    layer.confirm(
      "确认退出登录吗？",
      { icon: 3, title: "提示" },
      function (index) {
        //do something
        localStorage.removeItem("token");
        location.href = "login.html";
      }
    );
  });

  
});
function getUserInfo() {
  $.ajax({
    method: "GET",
    url: "/my/userinfo",
    success(res) {
      if (res.status != 0) return layui.layer.msg(res.message);
      readerAvatar(res.data);
    },
  });
}
//渲染用户信息
function readerAvatar(user) {
  let username = user.nickname || user.username;
  $("#welcome").html("欢迎&nbsp;&nbsp;" + username);
  if (user.user_pic) {
    $(".layui-nav-img").show().attr("src", user.user_pic);
    $(".text-avatar").hide();
  } else {
    $(".layui-nav-img").hide();
    $(".text-avatar").html(username[0].toUpperCase()).show();
  }
}
